package com.etennis.utils;

public class RecordProcessor {
    public double winnerScore=10;

    // 局分合法性检验
    public String isValidRecord(int pointA,int pointB){
        String result="invalid";

        if(pointA==6&&(pointB<5&&pointB>-1)||(pointA>-1&&pointA<5)&&pointB==6
                ||pointA==7&&(pointB==5||pointB==6)){
            result="valid";
        }
        return result;
    }

    // single record
    public static class SingleRecord{
        private final Double recordScore=20.0;
        private final Double winnerBonus=5.0;
        private final Double challengerBonusRate=0.1;

        private Long groupIdA;
        private Long groupIdB;
        private int pointA;
        private int pointB;
        private Double scoreA;
        private Double scoreB;

        // 构造
        public SingleRecord(Long groupIdA, Long groupIdB, int pointA, int pointB) {
            this.groupIdA = groupIdA;
            this.groupIdB = groupIdB;
            this.pointA = pointA;
            this.pointB = pointB;
        }

//        // 局分合法性检验
//        public String isValidSingle(){
//            String result="invalid";
//
//            if(pointA==6&&(pointB<5&&pointB>-1)||(pointA>-1&&pointA<5)&&pointB==6
//                    ||pointA==7&&(pointB==5||pointB==6)){
//                result="valid";
//            }
//            return result;
//        }

        // 单打比赛积分计算
        public void singleScoreCalculator(){
            // 基于赛局质量的积分分配
            this.scoreA=recordScore*pointA/(pointA+pointB);
            this.scoreB=recordScore*pointB/(pointA+pointB);

            // winner奖励分
            if(pointA>pointB){
                this.scoreA+=winnerBonus;
            }else if (pointA<pointB){
                this.scoreB+=winnerBonus;
            }

            // challenger奖励分
            if(this.groupIdA<this.groupIdB){
                this.scoreB+=this.scoreB*challengerBonusRate*(this.groupIdB-this.groupIdA);
            }else if(this.groupIdA>this.groupIdB){
                this.scoreA+=this.scoreA*challengerBonusRate*(this.groupIdA-this.groupIdB);
            }

        }

    }

    // double record
    public static class DoubleRecord{
        private final Double recordScore=40.0;
        private final Double winnerBonus=5.0;
        private final Double challengerBonusRate=0.1;
        private final Long groupGap=5L;

        private Long groupIdA1;
        private Long groupIdA2;
        private Long groupIdB1;
        private Long groupIdB2;
        private int pointA;
        private int pointB;
        private Double scoreA1;
        private Double scoreA2;
        private Double scoreB1;
        private Double scoreB2;

        // 构造
        public DoubleRecord(Long groupIdA1,Long groupIdA2,Long groupIdB1,Long groupIdB2,int pointA,int pointB) {
            this.groupIdA1 = groupIdA1;
            this.groupIdA2 = groupIdA2;
            this.groupIdB1 = groupIdB1;
            this.groupIdB2 = groupIdB2;
            this.pointA = pointA;
            this.pointB = pointB;
        }

        // 双打比赛积分计算
        public void doubleScoreCalculator(){
            // 基于赛局质量的组合积分分配
            Double scoreA=recordScore*pointA/(pointA+pointB);
            Double scoreB=recordScore*pointB/(pointA+pointB);

            // 双打组合水平评定
            Long groupA=groupIdA1+groupIdA2;
            Long groupB=groupIdB1+groupIdB2;

            // winner组合奖励分
            if(pointA>pointB){
                scoreA+=winnerBonus;
            }else if (pointA<pointB){
                scoreB+=winnerBonus;
            }

            // challenger组合奖励分
            if(groupA<groupB){
                scoreB+=scoreB*challengerBonusRate*(groupB-groupA);
            }else if(groupA>groupB){
                scoreA+=scoreA*challengerBonusRate*(groupA-groupB);
            }

            // 组内贡献度分配
            this.scoreA1=scoreA*(groupGap-groupIdA1)/groupA;
            this.scoreA2=scoreA*(groupGap-groupIdA2)/groupA;
            this.scoreB1=scoreB*(groupGap-groupIdB1)/groupB;
            this.scoreB2=scoreB*(groupGap-groupIdB2)/groupB;

        }
    }

}
